
#ifndef GKT_VOICE_H
#define GKT_VOICE_H

#include "gkt_voice_lib.h"

#ifdef __cplusplus
extern "C" {
#endif

enum {
	GKT_VOICE_OUTPUT_ST_FINISH = 0,
	GKT_VOICE_OUTPUT_ST_ERROR,
	GKT_VOICE_OUTPUT_ST_MAX
};

/*
 * maxnums of meta voice
 */
#ifdef GKT_CONFIG_VOICE_OUTPUT_META_MAXNUMS
#define GKT_VOICE_OUTPUT_META_MAXNUMS	GKT_CONFIG_VOICE_OUTPUT_META_MAXNUMS
#else
#define GKT_VOICE_OUTPUT_META_MAXNUMS	0x100
#endif

#if (GKT_VOICE_OUTPUT_META_MAXNUMS <= 0x100)
typedef uint8_t	gkt_voice_meta_id_t;
#else
typedef uint16_t	gkt_voice_meta_id_t;
#endif

typedef void (*gkt_voice_output_callback_fn)(uint32_t private_data, int result);

typedef struct _gkt_voice_combined_attr {
	uint32_t	meta_nums;
	const gkt_voice_meta_id_t	*meta_ids;
} gkt_voice_combined_attr_s;

#define GKT_VOICE_OUTPUT_PLAYBACK_TIMES_MAX	10000
#define GKT_VOICE_OUTPUT_PLAYBACK_INTERVAL_MAX	10000	/* unit in ms */
typedef struct _gkt_voice_output_playback_attr {
	uint32_t	times;	/* playback times, >= 1 */
	uint32_t	interval;	/* playback interval between 2 playbacks, unit in ms */
} gkt_voice_output_playback_attr_s;

#define GKT_VOICE_OUTPUT_PLAYBACK_ATTR_DEFINE(_times, _interval_ms)	\
	{	\
		.times	= _times,	\
		.interval	= _interval_ms,	\
	}

#if (defined(GKT_CONFIG_VOICE_OUTPUT_HARDWARE_B2206) \
		&& GKT_CONFIG_VOICE_OUTPUT_HARDWARE_B2206) \
	|| (defined(GKT_CONFIG_VOICE_OUTPUT_VOLUME_DISABLE) \
		&& GKT_CONFIG_VOICE_OUTPUT_VOLUME_DISABLE)
#define GKT_VOICE_OUTPUT_VOLUME_DISABLE	1
#else
#define GKT_VOICE_OUTPUT_VOLUME_DISABLE	0
#endif

typedef enum {
	GKT_VOICE_OUTPUT_VOLUME_HIGH = 0,
	GKT_VOICE_OUTPUT_VOLUME_MIDDLE,
	GKT_VOICE_OUTPUT_VOLUME_LOW,
	GKT_VOICE_OUTPUT_VOLUME_MAX
} gkt_voice_output_volume_e;

#define GKT_VOICE_OUTPUT_VOLUME_L1(amp_name)	\
	GKT_VOICE_OUTPUT_VOLUME_##amp_name
#define GKT_VOICE_OUTPUT_VOLUME(amp_name)	\
	GKT_VOICE_OUTPUT_VOLUME_L1(amp_name)

#ifdef GKT_CONFIG_VOICE_OUTPUT_VOLUME_DEFAULT
#define GKT_VOICE_OUTPUT_VOLUME_DEFAULT	\
	GKT_VOICE_OUTPUT_VOLUME(GKT_CONFIG_VOICE_OUTPUT_VOLUME_DEFAULT)
#else
#define GKT_VOICE_OUTPUT_VOLUME_DEFAULT	\
	GKT_VOICE_OUTPUT_VOLUME_MIDDLE
#endif

uint32_t gkt_voice_output_get_meta_nums(void);

#if !GKT_VOICE_OUTPUT_VOLUME_DISABLE
gkt_voice_output_volume_e gkt_voice_output_get_volume(void);
void gkt_voice_output_set_volume(gkt_voice_output_volume_e volume);
#else
#define gkt_voice_output_get_volume()	GKT_VOICE_OUTPUT_VOLUME_DEFAULT
#define gkt_voice_output_set_volume(amplitude)	\
	do { gkt_unused(amplitude); } while (0)
#endif

void gkt_voice_output_register_callback(gkt_voice_output_callback_fn callback);

/*
 * @function - gkt_voice_play
 * @brief    - play a combined voice which is composed of one or more meta voice
 * @params
 *   combined_attr  - [necessary] combined attr 
 *   params         - [optional]
 */
int gkt_voice_output_play(
				const gkt_voice_combined_attr_s *combined_attr,
				const gkt_voice_output_playback_attr_s *playback_attr,
				uint32_t private_data, uint32_t *duration_ms);

void gkt_voice_output_stop(void);

uint32_t gkt_voice_get_duration_ms(
			const gkt_voice_combined_attr_s *combined_attr,
			const gkt_voice_output_playback_attr_s *playback_attr)
;

void gkt_voice_output_opamp_init(void);
void gkt_voice_output_enable_opamp(void);
void gkt_voice_output_disable_opamp(void);

int gkt_voice_init(void);

#ifdef __cplusplus
}
#endif

#endif

